package com.operation.address;

import lombok.Data;

@Data
public class LogicAddress {

    private int pageNumber;
    private int pageAddress;

    /**
     * 将作业地址转化为页面地址
     * @param address 作业地址
     * @param pageSize 页面大小
     * @return 逻辑地址
     */

    public LogicAddress(long address,int pageSize) {
        this.pageNumber= (int) (address/pageSize);
        this.pageAddress= (int) (address%pageSize);
    }

    /**
     * 返回物理地址，同时打印输出
     * @param pageSize 页面大小
     * @param logicAddress 逻辑地址
     * @param memoryNumber 内存块号
     */
    public static long display(LogicAddress logicAddress,int memoryNumber,int pageSize){
        int pageNumber = logicAddress.getPageNumber();
        int pageAddress = logicAddress.getPageAddress();//页号和页内地址
        System.out.println("页号："+pageNumber+"----->内存块号："+memoryNumber+"----->页内地址："+pageAddress);
        long address = memoryNumber * pageSize + pageAddress;
        System.out.println("在内存中的物理地址："+address);
        return address;
    }

}
